<script>
	import {mapMutations} from 'vuex';
	import {networkStatus} from "./common/networkStatus.js";
	import appUpdate from "./common/appUpdate.js";
	export default {
		globalData:{ // 定义 某个页面 是否是通过uni.navigateBack(OBJECT) 返回的 0不是，1是
			backTo:0
		},
		methods: {
			...mapMutations(['signing', 'logout'])
		},
		onLaunch: function() {
			// 检测网络状态
			networkStatus.on();
			// 检测登录是否过期 验证token是否失效 失效则重新登录 
			let token = uni.getStorageSync('token') || '';
			let userInfo = uni.getStorageSync('userInfo') || '';
			let userID = uni.getStorageSync('userID') || '';
			let userType = uni.getStorageSync('userType') || '';
			let wkID = uni.getStorageSync('wkID') || '';
			let pm_company = uni.getStorageSync('pm_company') || '';
			
			
			if (token === "" || userInfo === "" || userID === "" || userType === "" || wkID === "" || pm_company === "") {
				this.logout()
			} else {
				uniCloud.callFunction({
					name: "validateToken",
					data: {
						token
					}
				}).then(res => {
					if (res.result.code !== 0) {
						uni.showToast({title:"重新登录",icon:"none"});
						this.logout();
					} else { // 验证成功更新登录状态
						let data = {
							token,
							userInfo,
							userID,
							userType,
							wkID,
							pm_company
						}
						this.signing(data);
					}
				})
			}
			
			// 检测小程序更新
			appUpdate.on();
		},
		onShow: function() {},
		onHide: function() {}
	}
</script>

<style lang="scss">
	/*页面的背景色*/
	page{
		background-color: #f6f6f7;
	}
	// 全局hover
	.h-class{
		background-color: #C8C7CC !important;
	}
	// ali图标
	@import "./common/ali-iconfont.css";
	// uview基础样式
	@import "uview-ui/index.scss";
	// container样式
	.container{
		padding: 20rpx;
	}
	//白色背景
	.container-bg{
		background: $uni-text-color-inverse;
	}
	.white-bg{
		background: $uni-text-color-inverse;
	}
	//阴影
	.z-b-s{
		box-shadow: 0 0 8rpx #C0C0C0;
	}
	//圆角
	.z-b-r{
		border-radius: 18rpx;
	}
	//统一背景色
	.z-bg-color{
		background: linear-gradient(to right, rgb(127, 127, 213), rgb(134, 168, 231), rgb(145, 234, 228));
	}
	//大号字体
	.z-font-lg{
		font-size: $uni-font-size-lg;
	}
	//白色字体
	.z-white-font{
		color: $uni-text-color-inverse;
	}
</style>
